Espresso might have worked better.
Here is another example problem that calls for nested IF
s:
An insurance company wants a program to calculate the annual premium for car insurance.
- The base rate is the annual premium in dollars for the car.
- The base rate is determined by the year and model of the car.
- A 5% discount applies to cars driven less than 20,000 miles a year.
- A 10% discount applies to cars driven less than 10,000 miles a year.
Our program will ask the user to enter the base rate from the keyboard. (A practical program would have this information in a file on the hard disk.)
The program will start out asking the user for data:
the BASERATE
and the
annual mileage.
Then the program will look the the mileage to figure out the DISCOUNT
.
The DISCOUNT
will be 0.0, 0.05, or 0.10 depending on the mileage.
The program will look like this:
PRINT "Please enter the base rate" INPUT BASERATE PRINT "Please enter annual mileage" INPUT MILEAGE Figure out the DISCOUNT PRINT "Your base rate is", BASERATE PRINT "Your discount is", DISCOUNT PRINT "You pay", BASERATE * (1 - DISCOUNT) END
The DISCOUNT will be one of three values. What control structure will be used?